KDPAT=SPACE(6)
DO WHILE .T.
   SET COLO TO BG+/B,W+/N
   @  7, 1 CLEA to  23,78
   @  8,11  SAY "SURNAME :                    FIRST NAME :"
   @ 17,13  SAY "ENTER THE SURNAME, THEN THE FIRST NAME OF THE PATIENT."
   @  7, 9  TO  9, 70    DOUBLE
   @ 16,11  TO 18, 68    DOUBLE
   sname=spac(16)
   fname=spac(16)
   @ 8,21 GET SNAME PICT '@!'
   @ 8,53 GET FNAME PICT '@!'
   READ
   if sname=space(16) .and. fname=space(16)
      @ 7,1 clea to 23,78
      ano='N'
      return
   endif
   OKK='F'
   DISP='T'
   @ 16,11 CLEA TO 18,68
   SET COLOR TO R+*/N
   @ 12, 25  SAY "Processing, Please wait ..."
   SET COLOR TO BG+/B, W+/N
   SELE 1
   SET EXCLU OFF
   USE &DR1&F1 INDE &DR1&F11, &DR1&F12
   sele 1
   set exclu off
   *key1=sname+fname
   key2=fname+sname
   *SET INDEX TO &DR1&F11
   *seek key1
   *if eof()
      SEEK KEY2
      IF EOF()
         SET INDEX TO &DR1&F12
         *seek key1
         *if eof()
            SEEK KEY2
            IF EOF()
               rec=recno()
               OKK='F'
               do PCON10
               sname=pat_name
               fname=pat_f_name
            ELSE
               kdpat=pat_filcod
               rec=RECNO()
               DISP='Y'
               OKK='T'
            ENDIF
         *else
         *   kdpat=pat_filcod
         *   rec=RECNO()
         *   DISP='Y'
         *   OKK='T'
         *endif
      ELSE
         kdpat=pat_filcod
         rec=RECNO()
         DISP='Y'
         OKK='T'
      ENDIF
   *else
   *   rec=RECNO()
   *   kdpat=pat_filcod
   *   DISP='Y'
   *   OKK='T'
   *endif
   SELE 1
   DO WHILE OKK='T'
      IF DISP='Y'
         @ 4,38 CLEA TO 6,62
         @ 7,1 CLEA TO 23,78
         DO ADDRPCO1
         DO PCON30
         MX=0
         DO WHILE MX=0
            MX=INKEY()
         ENDDO
         DO CASE
            CASE MX=13
               CNAME=SNAME
               CFNAME=FNAME
               PREV='Y'
               BUL1=SUBSTR(DTOS(DATE()),5,2)+SUBSTR(DTOS(DATE()),3,2)
*               DO PCON13
               DO PCON12
               EXIT
            CASE MX=-1
               DO PCON10
               sname=pat_name
               fname=pat_f_name
            CASE MX=27
               EXIT
            OTHER
               LOOP
         ENDCASE
      ENDIF
   ENDDO
   return
ENDDO
